﻿using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
namespace WPFExcelReport
{
    public partial class UIEKADR : ViewBase
    {
        public VEKADR TMV
        {
            get
            {
                return (VEKADR)MV;
            }
        }
        public UIEKADR()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
        }

        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            dwVKVV = dwMaster;
            if(dwMaster==null)
            {
                 
            }
            else
            {
            }

        }

        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            base.Window_Loaded(sender, e);
        }

        public VKUNDADR KDR;
        public  DataTable TBDKDR;
        public void GetVKAddress(DataRow dwVKAD, string _ADRSL)
        {
            if (TBDKDR == null)
                return;
            filter = "KDAADRSL='" + _ADRSL+"'";
            rows = TBDKDR.Select(filter);
            if (rows.Length == 0)
            {
                filter = "KDAADRSL='VK      '";
                rows = TBDKDR.Select(filter);
            }
            if (rows.Length == 0)
                return;
            foreach (DataRow row in rows)
            {

                dwVKAD["VKABNAME1"] = row["KDANAME1"];
                dwVKAD["VKABNAME2"] = row["KDANAME2"];
                dwVKAD["VKABSTRASSE1"] = row["KDASTRASSE1"];
                dwVKAD["VKABSTRASSE2"] = row["KDASTRASSE2"];
                dwVKAD["VKABLKZ"] = row["KDALAND"];
                dwVKAD["VKABPLZ"] = row["KDAPLZ"];
                dwVKAD["VKABORT"] = row["KDAORT"];

                dwVKAD["VKAANZ2"] = "01";
                dwVKAD["VKAADRSLK12"] = row["KDAADRSL"];
                dwVKAD["VKAKUNDNRK12"] = row["KDAKUNDNR"];
                dwVKAD["VKAANZK12"] = "01";
                break;
            }
        }
        public void GetVVAddress(DataRow dwVKAD, string _ADRSL)
        {
            if (TBDKDR == null)
                return;
            filter = "KDAADRSL='" + _ADRSL + "'";
            rows = TBDKDR.Select(filter);
            if (rows.Length == 0)
            {
                filter = "KDAADRSL='VK      '";
                rows = TBDKDR.Select(filter);
            }
            if (rows.Length == 0)
                return;
            foreach (DataRow row in rows)
            {
                dwVKAD["VKALNAME1"] = row["KDANAME1"];
                dwVKAD["VKALNAME2"] = row["KDANAME2"];
                dwVKAD["VKALSTRASSE1"] = row["KDASTRASSE1"];
                dwVKAD["VKALSTRASSE2"] = row["KDASTRASSE2"];
                dwVKAD["VKALLKZ"] = row["KDALAND"];
                dwVKAD["VKALPLZ"] = row["KDAPLZ"];
                dwVKAD["VKALORT"] = row["KDAORT"];
                dwVKAD["VKAKUNDNR1"] = row["KDAKUNDNR"];
                dwVKAD["VKAANZ1"] = "01";
                dwVKAD["VKAADRSLK11"] = row["KDAADRSL"];
                dwVKAD["VKAKUNDNRK11"] = row["KDAKUNDNR"];
                dwVKAD["VKAANZK11"] = "01";
            }
        }
        public void GetVRAddress(DataRow dwVKAD, string _ADRSL)
        {
            if (TBDKDR == null)
                return;
            filter = "KDAADRSL='" + _ADRSL + "'";
            rows = TBDKDR.Select(filter);
            if (rows.Length == 0)
            {
                filter = "KDAADRSL='VK      '";
                rows = TBDKDR.Select(filter);
            }
            if (rows.Length == 0)
                return;
            foreach (DataRow row in rows)
            {
                dwVKAD["VKAADRSL3"] = row["KDAADRSL"];
                dwVKAD["VKAKUNDNR3"] = row["KDAKUNDNR"];
                dwVKAD["VKAANZK22"] = "00";
                dwVKAD["VKAANZK13"] = "00"; 
            }
        }

        public override void ManageCommand(object sender, RoutedEventArgs e)
        {
            if (IsManage)
            {

            }
            else
            {
                VICC_WFEVENTS.SVWF.EK08(RUNID, ORDERNUM);
            }
            base.ManageCommand(sender, e);
        }

        public virtual void OnVVTChg(string vvt)
        {
        }

        public virtual void OnVKPChg(string vvt)
        {
        }
    }
    public partial class UIEKADR : ViewBase
    {
        #region ==VKP===========
        public static readonly DependencyProperty VKPProperty = DependencyProperty.Register("VKP",
            typeof(string), typeof(UIEKADR),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnVKPChanged));
        public string VKP
        {
            get
            {
                return (string)GetValue(VKPProperty);
            }
            set
            {
                SetValue(VKPProperty, value);
                OnVKPChg(value);
            }
        }
        private static void OnVKPChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIEKADR;
            if (src != null)
            {
                src.VKP = (string)e.NewValue;
            }
        }
        #endregion

        #region ==KASA===========
        public static readonly DependencyProperty KASAProperty = DependencyProperty.Register("KASA",
            typeof(string), typeof(UIEKADR),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKASAChanged));
        public string KASA
        {
            get
            {
                return (string)GetValue(KASAProperty);
            }
            set
            {
                SetValue(KASAProperty, value);
            }
        }
        private static void OnKASAChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIEKADR;
            if (src != null)
            {
                src.KASA = (string)e.NewValue;
            }
        }
        #endregion

        #region ==KDAD===========
        public static readonly DependencyProperty KDADProperty = DependencyProperty.Register("KDAD",
            typeof(string), typeof(UIEKADR),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKDADChanged));
        public string KDAD
        {
            get
            {
                return (string)GetValue(KDADProperty);
            }
            set
            {
                SetValue(KDADProperty, value);
            }
        }
        private static void OnKDADChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIEKADR;
            if (src != null)
            {
                src.KDAD = (string)e.NewValue;
            }
        }
        #endregion

        #region ==KUNDNR===========
        public static readonly DependencyProperty KUNDNRProperty = DependencyProperty.Register("KUNDNR",
            typeof(string), typeof(UIEKADR),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKUNDNRChanged));
        public string KUNDNR
        {
            get
            {
                return (string)GetValue(KUNDNRProperty);
            }
            set
            {
                SetValue(KUNDNRProperty, value);
            }
        }
        private static void OnKUNDNRChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIEKADR;
            if (src != null)
            {
                src.KUNDNR = (string)e.NewValue;
            }
        }
        #endregion

        #region ==dwKDR===========
        public static readonly DependencyProperty dwKDRProperty = DependencyProperty.Register("dwKDR",
            typeof(DataRow), typeof(UIEKADR),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OdwKDRChanged));
        public DataRow dwKDR
        {
            get
            {
                return (DataRow)GetValue(dwKDRProperty);
            }
            set
            {
                SetValue(dwKDRProperty, value);
            }
        }
        private static void OdwKDRChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIEKADR;
            if (src != null)
            {
                DataRow row = (DataRow)e.NewValue;
                src.dwKDR = row;
            }
        }
        #endregion

        #region ==VVT===========
        public static readonly DependencyProperty VVTProperty = DependencyProperty.Register("VVT",
            typeof(string), typeof(UIEKADR),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnVVTChanged));
        public string VVT
        {
            get
            {
                return (string)GetValue(VVTProperty);
            }
            set
            {
                SetValue(VVTProperty, value);
                OnVVTChg(value);
            }
        }
        private static void OnVVTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIEKADR;
            if (src != null)
            {
                src.VVT = (string)e.NewValue;
            }
        }
        #endregion

        #region ==dwVKVV===========
        public static readonly DependencyProperty dwVKVVProperty = DependencyProperty.Register("dwVKVV",
            typeof(DataRow), typeof(UIEKADR),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OdwVKVVChanged));
        public DataRow dwVKVV
        {
            get
            {
                return (DataRow)GetValue(dwVKVVProperty);
            }
            set
            {
                SetValue(dwVKVVProperty, value);
            }
        }
        private static void OdwVKVVChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIEKADR;
            if (src != null)
            {
                DataRow row = (DataRow)e.NewValue;
                src.dwVKVV = row;
            }
        }
        #endregion
    }
}
